<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<%@include file="/common/head.jsp" %>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="row">
		<div class="col-sm-12">
			<div class="ibox float-e-margins">
				<div class="ibox-content">
					<form role="form" class="form-inline" id="query-form" method="post" action="${ctx }/admin/employee/list" >
						<!-- 查询开始 -->
						<div class="form-group">
							<label for="query-user" class="sr-only2">用户ID</label>
							<input type="text" id="query-user-id" name="user.id"  class="form-control">
							<input type="hidden" class="form-control" id="user-name" name="user.id" value="${query.user.id }"
								   onclick="bring({
										   url:'${ctx}/admin/user/list',
										   name: 'id',
										   idInput: 'user-id',
										   nameInput: 'user-name'
										   })" />
						</div>
						<div class="form-group">
							<label for="query-name" class="sr-only2">姓名</label>
							<input type="text" id="query-name" name="name" value="${query.name }" class="form-control input-sm">

						</div>
						<div class="form-group">
							<label for="query-phone" class="sr-only2">联系电话</label>
							<input type="text" id="query-phone" name="phone" value="${query.phone }" class="form-control input-sm">

						</div>
						<div class="form-group">
							<label for="query-status" class="sr-only2">员工状态/1.录用/2.停职</label>
							<input type="text" id="query-status" name="status" value="${query.status }" class="form-control input-sm">

						</div>
						<div class="form-group">
							<button class="btn btn-primary btn-sm" type="submit"><i class="fa fa-search"></i>&nbsp;查询</button>
						</div>
						<!-- 查询结束 -->
					</form>

					<div>
						<p>
							<button type="button" class="btn btn-sm btn-outline btn-primary" onclick="add()" ><i class="fa fa-plus"></i> 新增</button>
							<button type="button" class="btn btn-sm btn-outline btn-info " onclick="edit()"><i class="fa fa-paste"></i> 详情</button>
							<%--<button type="button" class="btn btn-sm btn-outline btn-danger" onclick="del()">删除</button>--%>
							<button type="button" class="btn btn-sm btn-outline btn-info " onclick="reOpen()"><i class="fa fa-refresh"></i> 刷新</button>
						</p>
					</div>
					<table id="table" data-toggle="table" data-striped="true" data-click-to-select="true" data-mobile-responsive="true">
						<thead>
						<tr>
							<th data-field="_state" data-checkbox="true"></th>
							<th data-field="id" data-visible="false">ID</th>
							<th data-field="user">用户ID</th>
							<th data-field="position">岗位</th>
							<th data-field="department">部门</th>
							<th data-field="name">姓名</th>
							<th data-field="birth">出生日期</th>
							<th data-field="sex">性别</th>
							<th data-field="height">身高</th>
							<th data-field="weight">体重</th>
							<th data-field="place">籍贯</th>
							<th data-field="nation">民族</th>
							<th data-field="phone">联系电话</th>
							<th data-field="iDCard">身份证号</th>
							<th data-field="school">毕业学校</th>
							<th data-field="major">专业</th>
							<th data-field="education">学历</th>
							<th data-field="location">户口所在地</th>
							<th data-field="address">居住地址</th>
							<th data-field="wechat">微信号</th>
							<th data-field="email">邮箱</th>
							<th data-field="marry">婚姻状况</th>
							<th data-field="inTime">入职时间</th>
							<th data-field="status">员工状态/1.录用/2.停职/3.转正</th>
						</tr>
						</thead>
						<tbody>
						<c:forEach items="${list }" var="n" varStatus="idx">
							<tr data-index="${idx.index }" data-id="${n.id }">
								<td class="bs-checkbox">
									<input data-index="0" name="btSelectItem" type="checkbox">
								</td>
								<td style="">${n.id }</td>
								<td style="">${n.user.id}</td>
								<td style="">${n.position }</td>
								<td style="">${n.department.name}</td>
								<td style="">${n.name }</td>
								<td style="">
									<fmt:formatDate value="${n.birth }" pattern="yyyy-MM-dd"/>
								</td>
								<c:if test="${n.sex ==1}"><td style="">男</td></c:if>
								<c:if test="${n.sex ==0}"><td style="">女</td></c:if>
								<td style="">${n.height }</td>
								<td style="">${n.weight }</td>
								<td style="">${n.place }</td>
								<td style="">${n.nation }</td>
								<td style="">${n.phone }</td>
								<td style="">${n.IDCard }</td>
								<td style="">${n.school }</td>
								<td style="">${n.major }</td>
								<td style="">
									<c:if test="${n.education ==1}">
										大专
									</c:if>
									<c:if test="${n.education==2 }">
										本科
									</c:if>
									<c:if test="${n.education==3}">
										研究生
									</c:if>

								</td>
								<td style="">${n.location }</td>
								<td style="">${n.address }</td>
								<td style="">${n.wechat }</td>
								<td style="">${n.email }</td>
								<td style="">
									<c:if test="${n.marry ==1}">
										已婚
									</c:if>
									<c:if test="${n.marry==2 }">
										未婚
									</c:if>
								</td>
								<td style="">
									<fmt:formatDate value="${n.inTime }" pattern="yyyy-MM-dd"/>
								</td>
								<c:if test="${n.status==1}"><td style="">录用</td></c:if>
								<c:if test="${n.status ==2}"><td style="">停职</td></c:if>
								<c:if test="${n.status==3}"><td style="">录用</td></c:if>

									<%--<td>${enum:list('EmployeeStatus', n.status)}</td>--%>
							</tr>
						</c:forEach>
						</tbody>
					</table>

					<%@include file="/common/page.jsp" %>

				</div>
			</div>
		</div>
	</div>
</div>

<%@include file="/common/foot.jsp" %>
<script>
    function add() {
        layer.open({
            type: 2,
            skin: 'layui-layer-rim', //加上边框
            area: [layer_default_width, layer_default_height], //宽高
            content: "${ctx}/admin/employee/detail",
            btn: ['确定', '取消'],
            yes: function(index, layero){ //或者使用btn1
                var detailForm = layer.getChildFrame('form', index);
                console.log(detailForm);
                var position = $('#position', detailForm).val();
                if(!!!position){alert('请输入岗位.');return false;}
                var name = $('#name', detailForm).val();
                if(!!!name){alert('请输入姓名.');return false;}
                var birth = $('#birth', detailForm).val();
                if(!!!birth){alert('请输入出生日期.');return false;}
                var height = $('#height', detailForm).val();
                if(!!!height){alert('请输入身高.');return false;}
                var weight = $('#weight', detailForm).val();
                if(!!!weight){alert('请输入体重.');return false;}
                var place = $('#place', detailForm).val();
                if(!!!place){alert('请输入籍贯.');return false;}
                var nation = $('#nation', detailForm).val();
                if(!!!nation){alert('请输入民族.');return false;}
                var phone = $('#phone', detailForm).val();
                if(!!!phone){alert('请输入联系电话.');return false;}
                var iDCard = $('#iDCard', detailForm).val();
                if(!!!iDCard){alert('请输入身份证号码.');return false;}
                var school = $('#school', detailForm).val();
                if(!!!school){alert('请输入毕业学校.');return false;}
                var major = $('#major', detailForm).val();
                if(!!!major){alert('请输入专业.');return false;}
                var location = $('#location', detailForm).val();
                if(!!!location){alert('请输入户口所在地.');return false;}
                var address = $('#address', detailForm).val();
                if(!!!address){alert('请输入居住地址.');return false;}
                var wechat = $('#wechat', detailForm).val();
                if(!!!wechat){alert('请输入微信号.');return false;}
                var email = $('#email', detailForm).val();
                if(!!!email){alert('请输入邮箱.');return false;}
                // var marry = $('#marry', detailForm).val();
                // if(!!!marry){alert('请输入婚姻状况.');return false;}
                var inTime = $('#inTime', detailForm).val();
                if(!!!inTime){alert('请输入入职时间.');return false;}
                var emailReg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
                if(!emailReg.test(email)) {
                    alert('请输入正确的邮箱.');
                    return false;
                }
                var heightReg = /^[0-9]*$/;
                if(!heightReg.test(height)) {
                    alert('身高请输入数字.');
                    return false;
                }
                var weightReg = /^[0-9]*$/;
                if(!weightReg.test(weight)) {
                    alert('体重请输入数字.');
                    return false;
                }
                // var marryReg = /^[0-9]*$/;
                // if(!marryReg.test(marry)) {
                //     alert('婚姻状况请输入数字.');
                //     return false;
                // }
                var phoneReg = /^[1][3,4,5,7,8][0-9]{9}$/;
                if(!phoneReg.test(phone)) {
                    alert('请输入正确的手机号码格式.');
                    return false;
                }
                var iDCardReg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
                if(!iDCardReg.test(iDCard)) {
                    alert('请输入正确的身份证号码.');
                    return false;
                }
                detailForm.ajaxSubmit({
                    success: function(data) {
                        if (isSuccess(data)) {
                            layer.close(index);
                            reload();
                        } else {
                        }
                    }
                });
            }, cancel: function(index){ //或者使用btn2
                //按钮【按钮二】的回调
            }
        });
        //k.layer.add("${ctx}/admin/employee/detail");
    }

    function edit() {
        var selections = $('#table').bootstrapTable('getAllSelections');
        if (selections.length != 1) {
            //添加js提示框
            alert("请选择对应的用户ID");
            error2(k.msg.requireOne);
            return;
        }
        var id = selections[0].id;
        k.layer.edit("${ctx}/admin/employee/detail?id=" + id);
    }
    var page = "${page.page}";
    function reload() {
        page_submit(page);
    }

    paging('pagination', ${page.totalPages}, ${page.page});



    function del() {
        var selections = $('#table').bootstrapTable('getAllSelections');
        if (selections.length < 1) {
            error('请选择要删除的记录');
            return;
        }
        if (window.confirm("是否确定要删除")) {
            var ids = new Array();
            for (var i = 0; i < selections.length; i++) {
                ids.push(selections[i].id);
            }
            $.ajax({
                url: "${ctx}/admin/employee/delete",
                data: {
                    ids: ids.join(',')
                },
                success: function(data) {
                    if (isSuccess(data)) {
                        reload();
                    }
                }
            });
        }else {

        }

    }

</script>
</body>
</html>